/**
 * 
 */
/* global variables */
var config = {}
	config.apiUrl = 'http://localhost/svn/api/index.php/api';
var homeApp = angular.module('homeApp',['ui.router']);
homeApp.config(function($stateProvider, $urlRouterProvider) {
	  //
	  // For any unmatched url, redirect to /state1
	  $urlRouterProvider.otherwise("/article");
	  //
	  // Now set up the states
	  $stateProvider
	    .state('article', {
	      url: "/article",
	      templateUrl: "templates/article.html",
	      controller: "article"
	    })
	    .state('article.subarticle', {
	      url: "/:subarticle",
	      templateUrl: "templates/article.subarticle.html",
	      controller: "article.subarticle"
	    })
	    .state('music', {
	      url: "/music",
	      templateUrl: "templates/music.html",
	      controller: "music"
	    })
	    .state('music.submusic', {
	      url: "/:submusic",
	      templateUrl: "templates/music.submusic.html",
	      controller: "mucsic.submusic"
	    })
	    .state('signin',{
	    	url:"/signin",
	    	templateUrl:"templates/signin.html",
	    	controller:"signin"
	    })
	    .state("signup",{
	    	url:"/signup",
	    	templateUrl:"templates/signup.html",
	    	controller:"signup"
	    });
	  
	});
homeApp.controller('article',['$scope','$http',function($scope,$http){
	$scope.article ={};
	$http({
  		url:[config.apiUrl,'article'].join('/'),
  		method:"GET",
  		//data: $.param($scope.article),
  		//headers : { 'Content-Type': 'application/x-www-form-urlencoded' } 
  	}).success(function(data){
  		$scope.article = data;
	});
}]);
homeApp.controller('signup',['$scope','$http',function($scope,$http){
	$scope.user = {};
	$http({
  		url:[config.apiUrl,'users/add'].join('/'),
  		method:"POST",
  		data: $.param($scope.user),
  		headers : { 'Content-Type': 'application/x-www-form-urlencoded' } 
  	}).success(function(data){
  		if(data && data==true){
  			alert(data);
  		}
	});
	
}]);